export function formatDateTime(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
    // 将字符串时间戳转换为数字（处理可能的字符串类型）
    const numTimestamp = typeof timestamp === 'string'
        ? parseInt(timestamp, 10)
        : timestamp;

    const date = new Date(numTimestamp);

    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return format
        .replace('YYYY', year)
        .replace('MM', month)
        .replace('DD', day)
        .replace('HH', hours)
        .replace('mm', minutes)
        .replace('ss', seconds);
}

export function verifyImageUrl(url) {
    return new Promise((resolve, reject) => {
        const img = new Image();
        img.onload = () => resolve();
        img.onerror = () => reject();
        img.src = url;
    });
}